package com.interview.manytomany.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.GenericGenerator;

@Entity(name = "two")
public class ManyTwo {
	@Id
	@GenericGenerator(name = "UUID", strategy = "uuid")
	@GeneratedValue(generator = "UUID")
	private String id;

	private int age;
	// CascadeType.PERSIST
	//REFRESH, 
	//CascadeType.REMOVE, CascadeType.PERSIST 
	@ManyToMany(cascade = {CascadeType.REFRESH,CascadeType.REMOVE }, fetch = FetchType.EAGER )
	@JoinTable(name = "one_two", joinColumns = { @JoinColumn(name = "two_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "one_id", referencedColumnName = "id") })
	private List<ManyOne> ones;

	public List<ManyOne> getOnes() {
		return ones;
	}

	public void setOnes(List<ManyOne> ones) {
		this.ones = ones;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

}
